package com.dragon.client.controller.wechat;

import com.dragon.common.model.Insert;
import com.dragon.common.model.ResponseData;
import com.dragon.logical.service.wechat.IWechatMenuService;
import com.dragon.repository.domain.dto.WechatMenuDTO;
import com.dragon.repository.domain.vo.WechatMenuVO;
import com.dragon.repository.entity.WechatMenu;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 微信自定义菜单 前端控制器
 * </p>
 *
 * @author sy
 * @since 2023-12-01
 */
@RestController
@RequestMapping("wechatMenu")
@Api(tags = "微信自定义菜单")
public class WechatMenuController {

    @Autowired
    IWechatMenuService service;

    @GetMapping("list")
    @ApiOperation(value = "列表")
    public ResponseData<List<WechatMenuDTO>> menuList(){
        List<WechatMenu> wechatMenus = service.wechatMenuList();
        return ResponseData.success(WechatMenuDTO.convertList(wechatMenus));
    }

    @PostMapping("add")
    @ApiOperation(value = "添加到数据库")
    public ResponseData addWechat(@RequestBody @Validated(Insert.class)WechatMenuVO vo){
        return ResponseData.success(service.addWechat(WechatMenuVO.convert(vo)));
    }

    @GetMapping("delete")
    @ApiOperation(value = "删除")
    public ResponseData deleteWechat(@ApiParam(name = "ids", value = "id集合", required = true, type = "string")
                                     @RequestParam String ids){
        service.deleteWechat(ids);
        return ResponseData.success();
    }

    @PostMapping("addWechatMenu")
    @ApiOperation(value = "添加到微信公众号")
    public ResponseData addWechatMenu(){
        service.addWechatMenu();
        return ResponseData.success();
    }

    @GetMapping("deleteWechatMenu")
    @ApiOperation(value = "删除微信公众号")
    public ResponseData deleteWechatMenu(){
        service.deleteWechatMenu();
        return ResponseData.success();
    }

}
